// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue';
import FastClick from 'fastclick';
import VueRouter from 'vue-router';
import App from './App';
import router from './router/index';
import '../src/assets/css/reset.css';
// 引入Vuex的store对象
import store from './store';
import { isWeiXin } from './util/unit.js';

import { ToastPlugin, ConfirmPlugin, LoadingPlugin } from 'vux';

// 过滤器
Vue.filter('getCN', function(value) {
  switch (value) {
    case -1:
      return '已作废';
      break;
    case 0:
      return '待支付';
      break;
    case 1:
      return '已支付';
      break;
    case 'calendar':
      return '历年真题';
      break;
    case 'plan':
      return '模拟考试';
      break;
    case 'chapter':
      return '章节训练';
      break;
    case 'dayly':
      return '每日一练';
    case 'exercise':
      return '随机刷题';
      break;
  }
});

Vue.use(ToastPlugin, { position: 'middle', type: 'text' });
Vue.use(LoadingPlugin);
Vue.use(ConfirmPlugin);

Vue.use(VueRouter);

// 路由拦截
router.beforeEach(async (to, from, next) => {
  const l = localStorage;
  if (!l.selectedProject && to.name !== 'pickProject') {
    router.push({ path: '/pickProject' });
  }
  next();
});

FastClick.attach(document.body);

Vue.config.productionTip = false;

/* eslint-disable no-new */
new Vue({
  router,
  store,
  render: h => h(App),
}).$mount('#app-box');
